package ljl.codetop300;

public class _9_is_palin_number {

  /**
   * 他们说难点是溢出
   */
  public boolean isPalindrome(int x) {
    if (x < 0 || x > 0 && x % 10 == 0) return false;
    int y = 0;
    while (x > y) {
      y = y * 10 + x % 10;
      x /= 10;
    }
    return x == y || x == y / 10;
  }

  /**
   * 这个解法也很不赖，不用考虑 0 结尾的和奇数位偶数位，情况更少
   */
  static class solution2 {
    public boolean isPalindrome(int x) {
      if(x < 0)
        return false;
      int cur = 0;
      int num = x;
      while(num != 0) {
        cur = cur * 10 + num % 10;
        num /= 10;
      }
      return cur == x;
    }
  }
}
